package com.buer.storage.controller;


import com.buer.storage.entity.Car;
import com.buer.storage.entity.CarCategorytwo;
import com.buer.storage.service.CarCategoryService;
import com.buer.storage.service.CarCategorytwoService;
import com.buer.storage.vo.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/CarCategorytwo")
public class CarCategorytwoController {
    @Resource
    private CarCategorytwoService carCategorytwoService;

    //增加车辆二级分类
    @PostMapping("/insertCarCategorytwo")
    public R add(@RequestBody CarCategorytwo carCategorytwo) {
        if (carCategorytwoService.insertCarCategorytwo(carCategorytwo) > 0) {
            return R.setR(1, "添加车辆二级分类成功", null);
        }
        return R.setR(0, "添加车辆二级分类失败", null);
    }

    //删除车辆二级分类
    @GetMapping("/deleteCarCategoryById")
    public R delete(Integer categoryTwoId) {
        if (carCategorytwoService.deleteCarCategorytwoById(categoryTwoId) > 0) {
            return R.setR(1, "删除车辆二级分类成功", null);
        }
        return R.setR(0, "删除车辆二级分类失败", null);
    }

    //修改车辆二级分类
    @PostMapping("/updateCarCategoryById")
    public R update(@RequestBody CarCategorytwo carCategorytwo){
        if (carCategorytwoService.updateCarCategorytwoById(carCategorytwo)>0){
            return R.setR(1,"修改车辆二级分类成功",null);
        }
        return R.setR(0,"修改车辆二级分类失败",null);
    }

    //查询所有车辆二级分类
    @GetMapping("/selectCarCategoryAll")
    public List<CarCategorytwo> selectCarCategoryAll(){
            return carCategorytwoService.selectCarCategorytwoAll();
    }

    @GetMapping("/selectCarById")
    public List<Car> selectCarById(Integer categoryTwoId){
        List<Car> cars = carCategorytwoService.selectCarById(categoryTwoId);
        return cars;
    }
}
